package leetcode.part3;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class S383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        if(ransomNote.length() > magazine.length()) {
            return false;
        }

        int[] cnt = new int[26];

        for(char c : magazine.toCharArray()) {
            cnt[c - 'a'] ++;
        }
        for(char c : ransomNote.toCharArray()) {
            cnt[c - 'a'] --;
            if(cnt[c - 'a'] < 0) {
                return false;
            }
        }
        return true;


    }

    @Test
    public void test() {
        String ransomNote = "a", magazine = "b";
        String ransomNote1 = "abd", magazine1 = "abccefe";
        System.out.println(canConstruct(ransomNote, magazine));
        System.out.println(canConstruct(ransomNote1, magazine1));
    }
}
